<?php
// 连接到数据库
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "huayuan";

$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接是否成功
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

// 获取前端传来的用户id和要移除的好友id
$user_id = intval($_GET['userId']); // 将user_id转换为整数
$friend_id_to_remove = $_GET['friendId'];

// 更新recommend_friends字段，移除指定的好友id
$sql = "UPDATE users 
        SET recommend_friends = REPLACE(recommend_friends, '$friend_id_to_remove', '')
        WHERE user_id = $user_id"; // 直接使用整数类型的user_id
$conn->query($sql);
if ($conn->affected_rows > 0) {
    echo "1";
} else {
    echo "错误: " . $sql . "<br>" . $conn->error;
}

// 关闭连接
$conn->close();
?>
